﻿using Com.Yonyou.Entity;
using SqlSugar;
using XiheNet;
using XiheNet.Data;

namespace Com.Yonyou.Serv
{
    public class YUserDefineServ
    {
        private readonly ILogger<YUserDefineServ> _logger;
        private IHelper _helper;
        public YUserDefineServ(
            ILogger<YUserDefineServ> logger
            , IHelper helper
        )
        {
            _logger = logger;
            _helper = helper;
        }

        /// <summary>
        /// 获得用友自定义档案列表
        /// </summary>
        /// <param name="dictName"></param>
        /// <returns></returns>
        public List<Eap_UserDefineArticleDict> GetDictList() {
            using SqlSugarClient db = _helper.GetSqlClient();
            try
            {
                return db.Queryable<Eap_UserDefineArticleDict>().ToList();
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 获得用友自定义档案明细
        /// </summary>
        /// <param name="dictName"></param>
        /// <returns></returns>
        public List<EAP_UserDefineArticleDTO> GetDictOption(string dictName)
        {
            using SqlSugarClient db = _helper.GetSqlClient();
            try
            {
                Eap_UserDefineArticleDict dict = db.Queryable<Eap_UserDefineArticleDict>()
                        .Where(t => t.Title == dictName)
                        .First();

                if (dict != null)
                {
                    return db.Queryable<EAP_UserDefineArticleDTO>().AS(dict.TableName)
                        .ToList();
                }
                else
                {
                    throw new Exception("获得字典记录失败");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
